<?php
include_once "lib/config.php";
include_once "header.php";

if(isset($_POST['User']['password']) && $_POST['User']['password']!="")
{
	$_POST['User']['password_encrypted']=base64_encode($_POST['User']['password']);
	$_POST['User']['password']=md5($_POST['User']['password']);
	
    DB::updateData("users",$_POST['User'],array("id"=>$_POST['user_id']));
    
    if(DB::$affectedrows>0)
	{
		$_SESSION['msg_success']="Success: Pasword changed successfully";
	}
	else
	{
		$_SESSION['msg_error']="Error: Password not updated";
	}
    
    ?>
    <script>
    window.location="dashboard.php";
    </script>
    <?php
	
}

$totaluserinfo=DB::fetch_array(DB::query("select id,email_id,full_name from users "));

?>
     <script type="text/javascript">
		$(function() {
			$('.password').pstrength();
			});
			
        </script>   
		<div class="container_12">
        

            
            <form name="frm" method="post" onsubmit="return valid_pwd();">
            <div class="grid_6">
            	
                <div class="module">
                     <h2><span>Change Password</span></h2>
                        
                     <div class="module-body">
                        <form action="">
                        	<?php
                        	if($user_details[0]['user_type']=="Admin" )
                        	{
                        		?>
                        	<p>
                                <label>User:</label>
                                <select class="input-short" name="user_id" id="userid">
			                     <?php 
								 for($i=0;$i<count($totaluserinfo);$i++)
								 {
								 ?>   
									<option value="<?php echo $totaluserinfo[$i]['id']; ?>" <?php if($totaluserinfo[$i]['id']==$user_details[0]['id']){ echo "selected"; } ?> ><?php echo trim($totaluserinfo[$i]['full_name']); ?></option>
								 <?php
								 }
								 ?>
			                      
			                    </select>
                                
                            </p>
                            <?php
                            }
                            else
                            {
								?>
								<input type="hidden" name="user_id" id="userid" value="<?php echo $user_details[0]['id']; ?>">
								<?php
							}
                            ?>
                            <p>
                                <label>Type in new password:</label>
                                <input class="input-medium password" type="password" id="new_pass" name="User[password]"/>
                            </p>
                            <p>
                                <label>Repeat password:</label>
                                <input type="password" class="input-medium password" id="confirm_pass" />
                            </p>
                            <fieldset>
                                <input class="submit-green" type="submit" value="Submit" /> 
                                <input class="submit-gray" type="reset" value="Cancel"/>
                            </fieldset>
                        </form>
                        
                     </div> <!-- End .module-body -->
                </div> <!-- End .module -->
                <div style="clear:both;"></div>
            </div>
            </form>
            
            <div style="clear:both;"></div>
            
            
            
        </div> <!-- End .container_12 -->
		
      